<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      vertical-align: top;
    }
    html,body{
      width: 100%;
      height: 100%;
    }
    img{
      width: 100%;
    }
    .main{
      width: 1001px;
      margin: 0 auto;
      margin-top: 10px;
    }
    .main img{
      width: 100%;
    }
    .fixed{
      position: fixed;
      left: 0;
      top: 0;
    }
  </style>
</head>
<body>
  <div class="top"><img src="images/top.png" alt=""></div>
  <div class="nav"><img src="images/nav.png" alt=""></div>
  <div class="main"><img src="images/main.png" alt=""></div>
  <script src="../../jquery-1.12.4.min.js"></script>
  <script>
    //给window设计滚动条事件
    $(window).scroll(function(e){
     if($(this).scrollTop() > $('.top').height()){
      $('.nav').addClass('fixed');
      $('.main').css('marginTop',$('.nav').height()+10);
     }else{
       $('.nav').removeClass('fixed');
       $('.main').css('marginTop',10);
     };
    });
  </script>
</body>
</html>